package com.hosp.controller.v1;

import com.github.pagehelper.PageInfo;
import com.hosp.bean.Hosregister;
import com.hosp.controller.dto.RegistrationDTO;
import com.hosp.service.RegistrationService;
import com.hosp.vo.PageRequestVO;
import com.hosp.vo.RegistrationVO;
import com.hosp.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 挂号管理 API
 *
 * @author bing.zhang06@hand-china.com 2021/10/2 16:14
 **/
@Slf4j
@RestController
@RequestMapping("/registration")
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;

    /**
     * 查询列表
     *
     * @param registrationDTO 查询条件
     * @param pageRequest     分页条件
     * @return 响应
     */
    @GetMapping("/list")
    public ResultVO<RegistrationVO> list(RegistrationDTO registrationDTO, PageRequestVO pageRequest) {
        log.debug("input is {}.", registrationDTO);
        PageInfo<RegistrationVO> pageInfo = registrationService.list(registrationDTO, pageRequest);
        return new ResultVO<>(pageInfo);
    }

    /**
     * 主键查询
     *
     * @param hosrId 查询条件
     * @return 响应
     */
    @GetMapping("/{hosrId}")
    public ResultVO<RegistrationVO> selectById(@PathVariable("hosrId") Integer hosrId) {
        RegistrationVO registrationVO = registrationService.selectById(hosrId);
        return new ResultVO<>(registrationVO);
    }

    /**
     * 保存
     *
     * @param hosregister 保存对象
     * @return 响应
     */
    @PostMapping("/save")
    public ResultVO<String> save(Hosregister hosregister) {
        log.debug("Hosregister is {}.", hosregister);

        boolean flag = registrationService.save(hosregister);

        if (flag) {
            return new ResultVO<>(200, "保存成功");
        } else {
            return new ResultVO<>(500, "保存失败");
        }
    }
}
